package com.heihei.authority.core.validate.code.sms;

import com.heihei.authority.core.properties.MySecurityProperties;
import com.heihei.authority.core.validate.code.ValidateCodeGenerator;
import com.heihei.authority.core.validate.code.generate.VerifyCodeUtils;
import com.heihei.authority.core.validate.code.image.ImageCode;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;
import java.awt.image.BufferedImage;

/**
 *  图形验证码  系统集成默认实现
 *
 * @version 1.0
 * @since JDK1.8
 * @author duanhengfei
 * @date 2021年04月11日 11:03:31
 */
@Component("smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Resource
    private MySecurityProperties mySecurityProperties;

    @Override
    public SmsCode generateCode(ServletWebRequest request) {
//        int length = ServletRequestUtils.getIntParameter(request.getRequest(), "length", mySecurityProperties.getCode().getImage().getLength());
        String code = RandomStringUtils.randomNumeric(mySecurityProperties.getCode().getSms().getLength());
        return new SmsCode(code, mySecurityProperties.getCode().getImage().getExpireIn());
    }

}
